<?php 

// 将数组中选中的项做标记
function array_mark($arr = array(),$data='',$eq='id',$additem = '_mark',$mark = 'checked',$checkp=false){
    if ($checkp) {
        $pid = array();
        foreach ($arr as $key => $value) {
            $pid[$value['pid']] = 1;
        }
    }
    $arr = is_array($arr)?$arr:false;
    $tmp = array();
    
    foreach ($arr as $v) {
        if (!$checkp || ($checkp && !$pid[$v['id']])) {
            $v[$additem] = in_array($v[$eq], (array)$data) ? $mark : '';
        }
        $tmp[] = $v;
    }
    return $tmp;
}